package com.zdsoft.blp.zongbuju.shouye.linliquan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.imageTrans.CircleImage;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.LinLi;

import java.util.List;

/**
 * Created by Administrator on 2016/9/1.
 */
public class LLPingLunAdapter extends BaseAdapter {
    private List<LinLi> list;
    private LayoutInflater inflater;
    private Context context;

    public LLPingLunAdapter(List<LinLi> list, Context context) {
        this.list = list;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.linli_pinglun_itme,null);
            holder=new ViewHolder();
            holder.title_name= (TextView) convertView.findViewById(R.id.title_name);
            holder.title_content= (TextView) convertView.findViewById(R.id.title_content);
            holder.pc_pinglun_time= (TextView) convertView.findViewById(R.id.pc_pinglun_time);
            holder.title_iv= (ImageView) convertView.findViewById(R.id.title_iv);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        LinLi user=list.get(position);
        holder.title_name.setText(user.getUsername());
        holder.pc_pinglun_time.setText(user.getDate());
        holder.title_content.setText(user.getContent());
        if (!"".equals(user.getPicPath())){
            Picasso.with(context).load(user.getPicPath()).transform(new CircleImage()).error(R.drawable.no_pic).placeholder(R.drawable.loading).into(holder.title_iv);
        }
        return convertView;
    }
    class ViewHolder{
        TextView title_name,title_content,pc_pinglun_time;
        ImageView title_iv;
    }
}
